<template>
    <div>

        <van-cell-group>
            <van-field v-model="course_name" label="课程" placeholder="请输入课程名称" />

            <van-field v-model="price" label="价格" placeholder="请输入课程价格" />
        </van-cell-group>


        <p>
            请选择您要添加课程的分类：
            <select v-model="cate_id">
                <option :value="cate.id" v-for="(cate, index) in cate_list" :key="index">{{cate.name}}</option>
            </select>
            
            <van-button type="primary" @click="buy">确认添加</van-button>
        </p>
    </div>
</template>

<script>

export default {
    data() {
        return {
            cate_list:[],
            cate_id:'',
            course_name:'',
            price:'',
            uid:localStorage.getItem('uid'),
            token:localStorage.getItem('token')
        }
    },

    mounted:function(){
        this.axios.get('http://localhost:8000/get_cate/').then(res=>{
            console.log(res.data)

            this.cate_list = res.data

        })
    },

    methods:{
        buy:function(){

            this.axios.post('http://localhost:8000/course/',this.qs.stringify({'course_name':this.course_name,
            'price':this.price,'uid':this.uid,'cate_id':this.cate_id,'token':this.token})).then(res=>{
                console.log(res.data)

                if (res.data == '添加成功'){
                    this.$toast('课程添加成功')
                }

            })
        }
    }
}
</script>

<style>

p{
    padding-left: 15px;
}


</style>